package controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import service.TeamService;
import service.impl.TeamServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * @author CY
 * @date 2022/12/17 18:06
 **/
@WebServlet("/judge")
public class JudgeTeamServlet extends HttpServlet {
    TeamService service= new TeamServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charset=utf-8");
        //Json解析
        final BufferedReader bufferedReader = new BufferedReader(req.getReader());
        String line = null;
        final StringBuilder json = new StringBuilder();
        while ((line = bufferedReader.readLine()) != null) {
            json.append(line);
        }
        final JSONObject jsonObject = JSON.parseObject(json.toString());
        int tid = jsonObject.getInteger("tid");
        JSONObject message= new JSONObject();

       if( service.teamIsFull(tid)>2){
           message.put("status","1");
           message.put("Msh","队伍已满员");
       }
       resp.getWriter().write(message.toString());
    }
}
